<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>知士荟</title>
    <link rel="stylesheet" href="../css/discuss-detail.css" />
    <link rel="stylesheet" href="../css/layui/css/layui.css" />
    <script type="text/javascript" src="../js/jquery.js"></script>
    <script type="text/javascript" src="../js/space-discuss-detail.js"></script>
</head>

<body>
<!--**************顶部导航****************-->
<%@include file="../jsp/common/nav.jsp"%>
<!--**************左侧导航****************-->
<%@include file="../jsp/common/sidebar-scroll.jsp"%>
<!--***************右侧话题详细界面*******************-->
<c:set var="user" value="${sessionScope.user}"/>
<c:set var="space" value="${sessionScope.space}"/>
<div class="right">
    <!-----标题导航------>
    <div class="discuss-nav">
        <span class="discuss-nav-title"><a href="/index/main?id=${user.id}">学习空间</a></span>
        >
        <span class="discuss-nav-title"><a href="/index/space-main?space_id=${space.id}&name=${space.name}">${space.name}</a></span>
        >
        <span class="discuss-nav-title"><a href="/discuss/space-discuss">讨论区</a></span>
        >
        <span>${discuss.title}</span>
    </div>
    <!-----话题创建信息----->
    <div class="discuss-info">
        <span><img src="../images/4.jpg" /></span>
        <span class="member-name">${discuss.user.username}</span>
        <span>创建于 <fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${discuss.createdate}" /></span>
    </div>
    <!-----话题详细内容信息----->
    <div class="discuss-context">
        <div class="context-title">
            <h3>
                <c:if test="${discuss.status==2||discuss.status==4}">
                    <font color="red">${discuss.title}</font>
                </c:if>
                <c:if test="${discuss.status==1||discuss.status==3}">
                    ${discuss.title}
                </c:if>
            </h3>
            <div class="operate">
                <span class="update"><a href="/discuss/goToUpdate?id=${discuss.id}" >编辑</a></span>
                <!--判断：只有发布该话题的用户才能进行删除操作-->
                <c:if test="${discuss.user.id==user.id}">
                    <span class="delete"><a href="javascript:Delete('/discuss/delete?id=${discuss.id}');">删除</a></span>
                </c:if>
            </div>
        </div>
        <!--显示标签-->
        <c:forEach items="${labelList}" var="label">
            <div class="context-label"><a>${label.name}</a></div>
        </c:forEach>
        <!--话题内容-->
        <div class="context-detail">${discuss.content}</div>
    </div>
    <!--设置话题状态-->
    <div class="setStatus">
            <span class="highlight">
            <form action="/discuss/setEssence">
                <input type="hidden" name="id" value="${discuss.id}">
                <c:if test="${discuss.status==1||discuss.status==3}">
                    <input type="submit" value="设为精华贴"/>
                </c:if>
                <c:if test="${discuss.status==2||discuss.status==4}">
                    <input type="submit" value="取消精华贴"/>
                </c:if>
            </form>
        </span>
        <span class="collect">
            <form action="/discuss/setCollect">
                <input type="hidden" name="id" value="${discuss.id}">
                <c:if test="${discuss.status==1||discuss.status==2}">
                    <input type="submit" value="设为收藏"/>
                </c:if>
                 <c:if test="${discuss.status==3||discuss.status==4}">
                     <input type="submit" value="取消收藏"/>
                 </c:if>
            </form>
        </span>
    </div>
    <!-----话题评论信息----->
    <div class="discuss-comment-info">
        <!-- 留言的表单 -->
        <form class="layui-form" action="/discuss/goToComment" method="post" style="width:90%;">
            <input type="hidden" name="discuss_id" value="${discuss.id}"/>
            <input type="hidden" name="author_id" value="${sessionScope.user.id}"/>
            <div class="layui-input-block" style="margin-left: 0;">
                <textarea placeholder="欢迎进行评论" name="content" class="layui-textarea" style="height: 150px;"></textarea>
            </div>
            <br/>
            <div class="layui-input-block" style="text-align:left;right: 0;">
                <input type="submit" class="layui-btn" value="评论">
            </div>
        </form>
        <br/>
        <!-- 留言信息列表展示 -->

        <!--评论内容-->
        <c:forEach items="${commentList}" var="comment">
            <div class="comment-item" id="item1">
                <div class="member-info">
                    <span><img src="../images/4.jpg" /></span>
                    <span class="member-name">
                        <a href="/users/user-dongtai?id=${comment.user.id}" >${comment.user.username}</a>
                    </span>
                    <span class="createTime">创建于：<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${comment.createdate}" /></span>
                    <span class="edit">
                        <!--判断：只有发布该评论的用户才能进行删除操作-->
                        <c:if test="${comment.user.id==user.id}">
                            <a href="/discuss/deleteComment?comment_id=${comment.id}&discuss_id=${discuss.id}">删除</a>
                        </c:if>
                    </span>
                    <span class="reply"><a href="javascript:void(0)" onclick="replyBtn(this)">回复</a></span>
                </div>
                <div class="comment-info">
                        ${comment.content}
                    <!---回复列表--->
                    <c:forEach items="${replyList}" var="reply">
                        <c:if test="${comment.id==reply.comment.id}">
                            <div class="comment-item">
                                <div class="member-info">
                                    <span><img src="../images/4.jpg" /></span>
                                    <span class="member-name">
                                        <a href="/users/user-dongtai?id=${reply.author.id}" >${reply.author.username}</a>
                                        回复<a href="/users/user-dongtai?id=${reply.user.id}">@${reply.user.username}</a>
                                    </span>
                                    <span class="createTime">
                                    回复时间：<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${reply.createdate}"/>
                                    </span>
                                    <span class="edit"><a href="/discuss/deleteReply?reply_id=${reply.id}&discuss_id=${discuss.id}">删除</a></span>
                                    <span class="reply"><a href="javascript:void(0)" onclick="replyBtn(this)">回复</a></span>
                                </div>
                                <div class="comment-info">
                                        ${reply.content}
                                </div>
                            </div>

                            <form class="layui-reply-form" action="/discuss/reply?comment_id=${comment.id}&discuss_id=${discuss.id}" method="post" style="width:90%;">
                                <div class="layui-input-block" style="margin-left: 0;">
                                    <input type="hidden" name="member_id" value="${reply.author.id}">
                                    <textarea name="content" placeholder="请输入你的留言" class="layui-reply-textarea" style="height:50px;"></textarea>
                                </div>
                                <br/>
                                <div class="layui-input-block" style="text-align:left;right: 0;">
                                    <input type="button" class="layui-recover" onclick="recover()" value="取消">
                                    <input type="submit" class="layui-reply-btn" value="回复">
                                </div>
                            </form>
                        </c:if>
                    </c:forEach>
                </div>
            </div>

            <form class="layui-reply-form" action="/discuss/reply?comment_id=${comment.id}&discuss_id=${discuss.id}" method="post" style="width:90%;">
                <div class="layui-input-block" style="margin-left: 0;">
                    <input type="hidden" name="member_id" value="${comment.user.id}">
                    <textarea placeholder="请输入你的留言" name="content" class="layui-reply-textarea" style="height:50px;"></textarea>
                </div>
                <br/>
                <div class="layui-input-block" style="text-align:left;right: 0;">
                    <input type="button" class="layui-recover" onclick="recover()" value="取消">
                    <input type="submit" class="layui-reply-btn" value="回复">
                </div>
            </form>
        </c:forEach>
        <!--当查询结果没有时，给用户提示信息： -->
        <li style="border-top:1px solid #ccc;height: 40px;line-height: 40px;" >
            <center><font color="gray" size="2"  >${requestScope.msg}</font></center>
        </li>
    </div>
</div>
</body>
</html>